#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/10/30 11:09
# @Author  : zhaowp1109
# @File    : __init__.py.py
# @Description :

from sqlalchemy import Column, ForeignKey, Integer, \
    String,func,DateTime,SmallInteger,Text
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Mapped
from app.db.base_class import Base
from snowflake import SnowflakeGenerator
def gen_id():
    gen = SnowflakeGenerator(32)
    return next(gen)

class PostsCategory(Base):

    name = Column(String(128),default="", comment='名称')
    parent_id = Column(Integer,default=0,comment='父级')
    sort = Column(SmallInteger,default=1,comment="排序")

    __tablename__ = 'posts_category'
    __table_args__ = ({'comment': '分类'})

class Posts(Base):

    uid = Column(Integer,default=gen_id,comment="uid")
    category_id = Column(Integer, ForeignKey("posts_category.id"))
    category_name = Column(String(128),default="",comment="类型")
    title = Column(String(256),default="",comment="标题")
    content = Column(Text, comment="详情")
    topic = Column(String(256),default="",comment="话题")
    time_task = Column(DateTime, default=0, comment="有效时间")

    __table_args__ = ({'comment': '分发内容'})

class PostsMedia(Base):

    posts_id: Mapped[int] = mapped_column(ForeignKey("posts.id"), index=True)
    file_id = Column(Integer,comment="文件ID")
    url = Column(String(256),default="",comment="链接地址")
    __table_args__ = ({'comment': '图片和视频'})

